<?php
/**
 * Created by PhpStorm.
 * User: 水木易安
 * Date: 2017-2-16
 * Time: 12:44
 */

namespace app\Rong\controller;

use Rong\Api;
use think\Controller;

class Index extends Controller
{
    public function _initialize()
    {
        if (!uid()) {
            $this->error("未登录");
        }
    }

    public function index()
    {
        $RongCloud = new Api\RongCloud(config('Rong.appKey'), config('Rong.appSecret'));

        $user = session('user');

        $result = $RongCloud->user()->getToken($user['id'], $user['username'], '/');

        $result = json_decode($result, true);

        $result['chatroom'] = $RongCloud->chatroom()->create([
            "web" => "web",
            "shiper" => "shiper",
            "master" => "master"
        ]);

        $result['join_web'] = $RongCloud->chatroom()->join($user['id'], 'web');

        if (isShiper()) {
            $result['join_shiper'] = $RongCloud->chatroom()->join($user['id'], 'shiper');
        }
        return json($result);
    }

}